<template>
  <view class="home-app d-flex flex-column">
    <recruitHome v-if="userType === '1'" ref="recruit"></recruitHome>
    <enterpriseHome ref="enterprise" v-else></enterpriseHome>
  </view>
</template>

<script>
import { mapState } from "vuex";

// import enterpriseHome from "@/pages/enterprise/home/index.vue";
import enterpriseHome from "@/components/enterprise/home.vue";
import recruitHome from "@/pages/recruit/home/index.vue";
import { getInfo } from "@/api/login";

export default {
  components: {
    recruitHome,
    enterpriseHome,
  },
  data() {
    return {
      styleData: {
        topText: "",
        background: "#2eabee",
        TextColor: "#FFF",
      },
    };
  },
  computed: {
    ...mapState(["userType"]),
  },
  watch: {},
  async onLoad(options) {
    const type = this.$store.state.userType
    console.log(type, '首页');
    this.$store.dispatch("IsRecruit", type);
    if (options.phonenumber) {
      console.log('~~~', options)
      if (options.type == '1') {
        this.$store.commit("setUserType", "1");
      }
      if (options.type == '2') {
        this.$store.commit("setUserType", "2");
      }
      //记录扫码进来的数据标注为扫码用户
      this.$store.commit("steScanStatus", { storeId: options.storeId, isScan: 1, phonenumber: options.phonenumber });
      uni.setStorageSync('scanStatus', JSON.stringify({ ...options, isScan: 1 }))
      uni.setStorageSync('storeId', JSON.stringify(options.storeId))
    }
  },
  async onShow() {
    getInfo().then((res) => {
      if (res.code === 200) {
        if (res.data.storeStatus === '0') {
          uni.navigateTo({
            url: "/pages/recruit/login/selectStores/index",
          })
        }
      }
    })
    if (this.userType === '1') {
      // this.$refs.recruit && this.$refs.recruit.handleUpdate();
      this.$refs.recruit.pageNum = 1
      this.$refs.recruit && this.$refs.recruit.jobs();
    }
    if (this.userType === '2') {
      this.$refs.enterprise && this.$refs.enterprise.getCityInfo();
      // this.$refs.enterprise && this.$refs.enterprise.showDetail();
    }
  },
  onReady() {
  },
  methods: {},
  onBeforeUnmount() {
    if (this.userType === '1') {
      this.$refs.recruit.pageNum = 1;
    }
  },
  onShareAppMessage(res) {
    //console.log('onShareAppMessage',res);
    return {
      title: '自定义标题',
      path: 'pages/tabbarChange/firstPage/index',
    }
  },
  onShareTimeline() {
    return {
      title: '薪马马招聘'
    }
  }
};
</script>
<style lang="scss" scoped>
.home-app {
  position: relative;
  height: 100%;
}
</style>
